package edu.beyond.employment.talent.dao;

import java.util.List;

import edu.beyond.employment.commom.util.DBUtil;
import edu.beyond.employment.talent.entity.ResumeEntity;

/**
 * Dao(Data Access Object)：执行所有数据库的操作
 *
 * @author beyond.
 * @since 2016年1月11日
 */
public class ResumeDao {

	/**
	 * 简历新增
	 * 
	 * @param resumeEntity
	 * @return
	 */
	public int add(ResumeEntity resumeEntity) {
		int row = DBUtil.executeUpdate("INSERT INTO resume VALUES(NULL, ?, ?, ?, ?)", resumeEntity.getTalentId(),
				resumeEntity.getIntention(), resumeEntity.getWorkExperience(), resumeEntity.getProjectExperience());
		return row;
	}

	/**
	 * 简历查询
	 * 
	 * @param resumeEntity
	 * @return
	 */
	public List<ResumeEntity> list(int talentId) {
		List<ResumeEntity> resumeList = DBUtil.executeQuery(ResumeEntity.class,
				"SELECT id, intention, work_experience, project_experience FROM resume WHERE talent_id=? ORDER BY id DESC",
				talentId);
		return resumeList;
	}

	/**
	 * 简历删除
	 * 
	 * @param id
	 * @return
	 */
	public int delete(int id) {

		return DBUtil.executeUpdate("DELETE FROM resume WHERE id=?", id);
	}

	/**
	 * 简历修改前的查询（根据简历id查询简历的详细信息）
	 * 
	 * @param id
	 * @return
	 */
	public ResumeEntity get(int id) {

		return DBUtil.getUniqueResult(ResumeEntity.class, "SELECT * FROM resume  WHERE id =?", id);
	}

	/**
	 * 简历的真正修改
	 * 
	 * @param resumeEntity
	 * @return
	 */
	public int update(ResumeEntity resume) {

		return DBUtil.executeUpdate("UPDATE resume SET intention=?, work_experience=?, project_experience=? WHERE id=?",
				resume.getIntention(), resume.getWorkExperience(), resume.getProjectExperience(), resume.getId());
	}
}
